sprintf(filename, "c:\\temp\\settings-%06d.var", 123456);
f = fopen(filename, "wt");
if (f) {
h = supe->get_setting_ref(BASE_HASHVAR);
for (i = 0; i < NUM_HASHVARS; ++i, ++h) {
fprintf(f, "%d\t%f\n", i+BASE_HASHVAR, *h);
}
fclose(f);
printf("Wrote %d settings to %s on PC\n", NUM_HASHVARS, filename);
}
else
printf("Could not open %s on PC\n", filename);
Basically what I am doing is writing a file in NGC ".var" format, based on some configuration data on the kflop.
What is strange is that 'f' always seems to be NULL after fopen(), even though it does create a file on the PC. If I just ignore the fact that it is NULL and go ahead and use it, then it seems to write data.
On the PC, I can't open the file because Windows is saying that it is in use by another application. So it looks like fclose() is not getting through to the KMotion server to tell it to close the file.
So is the value of the FILE pointer on the kflop meaningful?
3. What happens if a thread forgets to fclose()?
4. When trying this out, I first used a relative path name, but then fopen() returned NULL, so I thought it wasn't supported. I then changed the path name to absolute, and again got the NULL. But this time I found the file in c:\temp, but it was empty. So finally I got rid of the NULL test. It wrote 5k data to the file, but now I cannot open thanks to Windows thinking it's in use.
What have I done wrong?
Regards,
SJH